// components/orderGoodsList/orderGoodsList.js
const defaultStyle = {
    style: 1,
    //1——横向滚动列表+列表信息（无商品状态），2——竖向列表+列表信息（无商品状态），3——横向滚动列表+商品状态（有详细列表弹窗），4横向滚动列表+商品状态（无详细列表弹窗）
    mainColor: "#47B34F",
    screenFull: true,
    styleConfig: {
        backgroundColor: "#fff"
    }
};

Component({
    /**
   * 组件的属性列表
   */
    options: {
        addGlobalClass: true
    },
    properties: {
        goodsListStyle: {
            type: Object,
            observer(newVal, oldVal, changPath) {
                let that = this;
                var comStyle = this.data.comStyle;
                var listStyle = that.data.listStyle;
                that.setData({
                    leaderName: newVal.leaderName,
                    comStyle: {
                        ...comStyle,
                        ...newVal
                    },
                    listStyle: {
                        ...listStyle,
                        style: newVal.style ? newVal.style : that.data.comStyle.style
                    }
                });
            }
        },
        goodsListData: {
            type: Array,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    listData: newVal
                });
            }
        },
        allExpressPro: {
            type: Array,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    allExpressPro: newVal
                });
            }
        },
        expressType: {
            type: Array,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    expressType: newVal
                });
            }
        },
        deliveryWay: {
            type: Number,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    delivery_way: newVal
                });
            }
        },
        url: {
            type: String,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    comUrl: newVal
                });
            }
        },
        delivery_fee_info: {
            type: Object,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    delivery_fee_info: newVal
                });
            }
        },
        is_seckill: {
            type: Number,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    is_seckill: newVal
                });
            }
        },
        full_discount: {
            type: Object,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    full_discount: newVal
                });
            }
        },
        total_money: {
            type: Number,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    total_money: newVal
                });
            }
        },
        enjoy_free_shipping: {
            type: Boolean,
            observer(newVal, oldVal, changePath) {
                this.setData({
                    enjoy_free_shipping: newVal
                });
            }
        }
    },
    /**
   * 组件的初始数据
   */
    data: {
        lamguage: "",
        isHidden: true,
        comStyle: {
            ...defaultStyle
        },
        listData: {
            totalNum: 1,
            deliveryWay: "",
            item: [ {
                id: "0",
                //商品id
                proId: 0,
                icon: "https://test-sqtgxt.hdewm.com/backend/web/uploads/Worldidc_156698046463.jpeg",
                //商品缩略图
                proName: "儿童超Q特技三轮",
                //商品名称
                spec: "重量:100g;",
                //规格
                refund_control: "1",
                //是否是满减商品
                spec_fund: 0,
                //
                price: "0.01",
                //商品单价
                num: "2",
                //数量
                status: "-1",
                //售后状态，-1——仅退款，-2—— 退货退款，-3退货换货
                order_status: "1",
                //订单状态,
                vip_price: 0,
                is_vip: 0
            } ]
        },
        listStyle: {}
    },
    /**
   * 组件的方法列表
   */
    methods: {
        goTo(e) {
            wx.navigateTo({
                url: e.currentTarget.dataset.url
            });
        },
        processData() {
            //计算商品总价格
            let that = this;
            var goods = that.data.goodsListData;
            var delivery_way = that.data.delivery_way;
            var delivery_fee_info = that.data.delivery_fee_info;
            var payMoney = 0;
            //实际支付的总价
                        var express_fee_toal = 0;
            var all_express_not = [];
            goods.forEach(item => {
                if (item.vip_enjoy_display == 1) {
                    payMoney += parseFloat(item.buy_num * item.vip_enjoy_price);
                } else {
                    payMoney += parseFloat(item.buy_num * item.price);
                }
                if (item.is_free_express == 1) {
                    express_fee_toal += parseFloat(item.buy_num * item.price);
                }
            });
            var all_express_not = goods.filter(item => {
                return item.is_free_express == 0;
            });
            var difference = 0;
            //总价-满减配送是否开启
                        if (delivery_way == 2 && delivery_fee_info.free_leader_delivery_switch == 1) {
                //团长配送
                difference = (parseFloat(that.data.delivery_fee_info.free_leader_delivery_condition) - parseFloat(payMoney)).toFixed(2);
            } else if (delivery_way == 3 && delivery_fee_info.free_esb_delivery_switch == 1) {
                //平台配送
                difference = (parseFloat(that.data.delivery_fee_info.free_esb_delivery_condition) - parseFloat(payMoney)).toFixed(2);
            } else if (delivery_way == 4 && delivery_fee_info.free_express_delivery_switch == 1) {
                //快递配送
                var payMoney_actually = parseFloat(payMoney) - parseFloat(express_fee_toal);
                difference = (parseFloat(that.data.delivery_fee_info.free_express_delivery_condition) - parseFloat(payMoney_actually)).toFixed(2);
            }
            that.setData({
                payMoney: payMoney.toFixed(2),
                trans_difference: difference,
                all_express_not: all_express_not
            });
        },
        hiddenModal(e) {
            this.setData({
                isHidden: e.detail.goodsIsHidden
            });
        }
    },
    lifetimes: {
        ready() {
            let that = this;
            that.processData();
        }
    },
    observers: {
        delivery_way: function() {
            this.processData();
        }
    }
});